#ifndef IMAGELOADER_H
#define IMAGELOADER_H

#include <QtGui/QDialog>
#include <QtCore>
#include <QtPlugin>
#include <QImage>
#include <QDir>
#include <string>
#include <QVector>
#include <QLabel>
#include <QPixmap>
#include <QSignalMapper>
#include <QToolButton>
#include <QStringList>
#include <QScrollBar>
#include <QIcon>
#include <cv.h>
#include <highgui.h>
#include <iostream>
#include <QFuture>
#include <QtConcurrentMap>
#include <QFutureWatcher>
#include <QProgressDialog>

#ifndef QT_NO_CONCURRENT

using namespace cv;
using namespace std;

namespace Ui {
    class ImageLoader;
}

class ImageLoader : public QDialog {
    Q_OBJECT
public:
    ImageLoader(QWidget *parent = 0);
    ~ImageLoader();
    void reload();
    void updateIcons(const QStringList& filter);
    void addFiles(const QVector<QString>& files);
    void addResultImg(const Mat &img);
    int getCurrIndex();
    int getLoadedSize() { return loadedFiles;}
    QString getCurrFile();
    QString getFileByIndex(int id);
    QVector<QString> getFiles() { return files;}
    Mat getResultImage() { return resultImg; }
    void clearDisplay();

public Q_SLOTS:
    void addButton(int);
    void finished();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::ImageLoader *m_ui;
    QVector<QString> files;
    QPointer<QSignalMapper> mapper;     // Map different icon for display purpose
    QString currFile;                   // Current image file
    QPointer<QScrollBar> bar;           // Scroll bar for image loader
    QToolButton* theButton;
    QFutureWatcher<QImage> *loader;     // Load images
    QList<QToolButton *> buttonList;
    QProgressDialog progress;
    Mat resultImg;                      // Result image
    int loadedFiles;

private slots:
    void displayImage(int);
    void moveLeft();
    void moveRight();
    void slideLeft();
    void slideRight();

signals:
    void imageSelected(const QString& file);
};

#else

// Dummy class required because QT_NO_CONCURRENT is not set when moc is running.
class ImageLoader : public QDialog {
    Q_OBJECT

    public Q_SLOTS:
        void addButton() {}
};

#endif // QT_NO_CONCURRENT
#endif // IMAGELOADER_H
